package springboot.springboot06_ssmp.service.impl;




import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import springboot.springboot06_ssmp.entity.SendBack;
import springboot.springboot06_ssmp.mapper.SendBackMapper;
import springboot.springboot06_ssmp.service.ISendBackService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author daiqiang
 * @since 2024-01-24
 */
@Service

public class SendBackServiceImpl extends ServiceImpl<SendBackMapper, SendBack> implements ISendBackService {

    @Autowired
    private SendBackMapper sendBackMapper;

   //批量添加
    @Override
    public void add(List<SendBack> list) {
        if(list != null && list.size() > 0) {
            for (SendBack sendBack : list) {
                /*//检查此数据（日期）是否存在
                long count = orderSettingDao.findCountByOrderDate(orderSetting.getOrderDate());
                if(count > 0){
                    //已经存在，执行更新操作
                    orderSettingDao.editNumberByOrderDate(orderSetting);
                }else{
                    //不存在，执行添加操作*/

                sendBackMapper.insert(sendBack);
            }
        }

    }

    @Override   //分页，模糊查询
    public IPage<SendBack> getPage(int currentPage, int pageSize, SendBack sendBack) {
        LambdaQueryWrapper<SendBack> lqw = new LambdaQueryWrapper<>();
        lqw.like(Strings.isNotEmpty(sendBack.getName()),SendBack::getName,sendBack.getName());
        lqw.like(Strings.isNotEmpty(sendBack.getAddress()),SendBack::getAddress,sendBack.getAddress());
        IPage page = new Page(currentPage,pageSize);
        sendBackMapper.selectPage(page,lqw);
        return  page;
    }

}
